set -e
set -o pipefail

if [ -z "${FORCE_LOW_HIGH_THRESHOLD}" ]; then FORCE_LOW_HIGH_THRESHOLD=1.0; fi
if [ -z "${OUTLIER_TEST}" ]; then OUTLIER_TEST=iqr2; fi
if [ -z "${KEEP_SUBSTRETCHES}" ]; then KEEP_SUBSTRETCHES=True; fi
if [ -z "${DIFFUSE_DISTRIBUTION}" ]; then DIFFUSE_DISTRIBUTION=normal; fi
if [ -z "${DIFFUSE_HALF_SUPPORT_UNITS}" ]; then DIFFUSE_HALF_SUPPORT_UNITS=60; fi
if [ -z "${FIT_METHODS}" ]; then FIT_METHODS="standard mle"; fi
if [ -z "${FIXED_MODULES}" ]; then FIXED_MODULES=0; fi

fixedDeflectionSensitivityNmPerV=$DEFL_SENS; fixedSpringConstantNPerM=$K; kineticsSuffix=${KINETICS_SUFFIX//*/_${KINETICS_SUFFIX}}; for d in $DIRS; do p=$(dirname ${d}); b=$(basename ${d})${fixedDeflectionSensitivityNmPerV//*/_${fixedDeflectionSensitivityNmPerV}}${fixedSpringConstantNPerM//*/_${fixedSpringConstantNPerM}}; (cd ~/work/rcs/refolding-read-only/core/src/main/python && python2.7 kinetics_opt_main.py --curve_stretch_playlists=${p}/analysis/${b}_analysis/kinetics_${OUTLIER_TEST}_${FORCE_LOW_HIGH_THRESHOLD}_${KEEP_SUBSTRETCHES}${kineticsSuffix}.curveStretchPlaylist --fixed_modules=${FIXED_MODULES} --seeds 0 --fit_methods ${FIT_METHODS} --diffuse_distribution=${DIFFUSE_DISTRIBUTION} --diffuse_half_support_units=${DIFFUSE_HALF_SUPPORT_UNITS} --results_repr=${p}/analysis/${b}_analysis/kinetics_${OUTLIER_TEST}_${FORCE_LOW_HIGH_THRESHOLD}_${KEEP_SUBSTRETCHES}${kineticsSuffix}_results.repr 2>&1 | tee ${p}/analysis/${b}_analysis/filtered.curveStretchPlaylist_${OUTLIER_TEST}_${FORCE_LOW_HIGH_THRESHOLD}_${OUTLIER_TEST}_${KEEP_SUBSTRETCHES}_${DIFFUSE_DISTRIBUTION}_${DIFFUSE_HALF_SUPPORT_UNITS}${kineticsSuffix}_fit.log); done
